<%@ page import="rcfirewall.conexaoBD,java.sql.*,javax.sql.*"%>
<%@ page import="java.io.*,java.util.*, javax.servlet.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Softpar Firewall</title>
</head>
<body>
<%
conexaoBD bd = new conexaoBD();
String source = request.getParameter("source");
String name = null;
ResultSet rs = bd.montaDropDown2("select * from DESTINATION where name = \'" + source + "\'");
if (rs.next() == true){
	source = rs.getString(2);
	name = rs.getString(1);
}

String ruleAdd = ("iptables -A FORWARD -s " + source + " -d 0/0 -m comment --comment \"Acesso Full " + name + "\" -j ACCEPT" );
String ruleDelete = ("iptables -D FORWARD -s " + source + " -d 0/0 -m comment --comment \"Acesso Full " + name + "\" -j ACCEPT" );

bd.insertBD("insert into RULES (ruleAdd) value ('"+ ruleAdd + "')");



String ID =null;
rs = bd.montaDropDown2("select * from RULES where ruleAdd ='" + ruleAdd + "'");
if (rs.next() == true){
	ID = rs.getString(1);
}

bd.insertBD("update RULES SET ruleDelete ='"+ ruleDelete +"', source ='" + 
		 source +  "', name ='" + name + "', type = '2' where id ='"+ ID +"'");


try {
	 
    String[] commands = new String[]{"iptables", "-A", "FORWARD" ,"-s", source, "-d", "0/0",
    		"-m", "comment", "--comment", "Acesso Full " + name + ". ID da Regra " + ID, "-j", "ACCEPT"};
    
    commands = new String[]{"iptables", "-A", "FORWARD" ,"-s", source, "-d", "0/0",
    		"-m", "comment", "--comment", "Acesso Full " + name + ". ID da Regra " + ID, "-j", "ACCEPT"};
            
    Process child = Runtime.getRuntime().exec(commands);
    
} catch (IOException e) {
}
%>


</body>
</html>